package com.medica.ledproject.socke;

/**
 * @author xiaona
 * @date 2024/5/30
 * @description TODO
 */

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.bytes.ByteArrayDecoder;
import io.netty.handler.codec.bytes.ByteArrayEncoder;
import org.springframework.stereotype.Component;

@Component
public class SocketInitializer extends ChannelInitializer<SocketChannel>
{
    protected void initChannel(SocketChannel socketChannel)
            throws Exception
    {
        ChannelPipeline pipeline = socketChannel.pipeline();

        pipeline.addLast(new ChannelHandler[] { new ByteArrayDecoder() });
        pipeline.addLast(new ChannelHandler[] { new ByteArrayEncoder() });

        pipeline.addLast(new ChannelHandler[] { new SocketHandler() });
    }
}